Return to start page
Systems/Character/Struct Shrine.j
1 library AStructSystemsCharacterShrine requires optional ALibraryCoreDebugMisc, AStructCoreGeneralHashTable, ALibraryCoreEnvironmentSound, ALibraryCoreEnvironmentSpecialEffect, AStructSystemsCharacterCharacter, AStructSystemsCharacterRevival
2
3 struct AShrine
4 //static start members
5 private static string effectPath
6 private static string soundPath
7 private static string textMessage
8 //start members
9 private destructable m_destructable
10 private rect m_discoverRect
11 private rect m_revivalRect
12 private real m_facing
13 //members
14 private trigger m_shrineTrigger
15 private region m_discoverRegion
16 private effect m_discoverEffect
17
18 //! runtextmacro optional A_STRUCT_DEBUG("\"AShrine\"")
19
20 //start members
21
22 public method destructable takes nothing returns destructable
23 return this.m_destructable
24 endmethod
25
26 public method discoverRect takes nothing returns rect
27 return this.m_discoverRect
28 endmethod
29
30 public method revivalRect takes nothing returns rect
31 return this.m_revivalRect
32 endmethod
33
34 public method facing takes nothing returns real
35 return this.m_facing
36 endmethod
37
38 //methods
39
40 public method enableForCharacter takes ACharacter character, boolean showMessage returns nothing
41 local player user = character.user()
42 if (ACharacter.playerCharacter(user).shrine() != 0) then
43 call ACharacter.playerCharacter(user).shrine().disableForCharacter(ACharacter.playerCharacter(user)) //disable old
44 endif
45 call character.setShrine(this)
46 call character.revival().setX(GetRandomReal(GetRectMinX(this.m_revivalRect), GetRectMaxX(this.m_revivalRect)))
47 call character.revival().setY(GetRandomReal(GetRectMinY(this.m_revivalRect), GetRectMaxY(this.m_revivalRect)))
48 call character.revival().setFacing(this.m_facing)
49 if (thistype.effectPath != null) then
50 set this.m_discoverEffect = CreateSpecialEffectForPlayer(user, thistype.effectPath, GetDestructableX(this.m_destructable), GetDestructableY(this.m_destructable))
51 endif
52 if (thistype.soundPath != null) then
53 call PlaySoundPathForPlayer(user, thistype.soundPath)
54 endif
55 if (showMessage) then
56 call character.displayMessage(ACharacter.messageTypeInfo, thistype.textMessage)
57 endif
58 set user = null
59 endmethod
60
61 private method disableForCharacter takes ACharacter character returns nothing
62 debug if (character.shrine() == this) then
63 call character.setShrine(0)
64 if (thistype.effectPath != null) then
65 call DestroyEffect(this.m_discoverEffect)
66 set this.m_discoverEffect = null
67 endif
68 debug else
69 debug call this.print("Is not the shrine of character " + I2S(character) + ".")
70 debug endif
71 endmethod
72
73 private method createDiscoverRegion takes nothing returns nothing
74 set this.m_discoverRegion = CreateRegion()
75 call RegionAddRect(this.m_discoverRegion, this.m_discoverRect)
76 endmethod
77
78 private static method triggerConditionEnable takes nothing returns boolean
79 local trigger triggeringTrigger
80 local unit triggerUnit = GetTriggerUnit()
81 local player owner = GetOwningPlayer(triggerUnit)
82 local thistype this
83 local boolean result = false
84 debug call Print("Shrine Condition")
85 if (triggerUnit == ACharacter.playerCharacter(owner).unit()) then
86 set triggeringTrigger = GetTriggeringTrigger()
87 set this = AHashTable.global().handleInteger(triggeringTrigger, "this")
88 set result = ACharacter.playerCharacter(owner).shrine() != this
89 //if (ACharacter.playerCharacter(owner).shrine() != this) then
90 //set result = ACharacter.playerCharacter(owner).isMovable()
91 //endif
92 set triggeringTrigger = null
93 endif
94 set triggerUnit = null
95 set owner = null
96 return result
97 endmethod
98
99 private static method triggerActionEnable takes nothing returns nothing
100 local trigger triggeringTrigger = GetTriggeringTrigger()
101 local unit triggerUnit = GetTriggerUnit()
102 local player owner = GetOwningPlayer(triggerUnit)
103 local thistype this = AHashTable.global().handleInteger(triggeringTrigger, "this")
104 call this.enableForCharacter(ACharacter.playerCharacter(owner), true)
105 set triggeringTrigger = null
106 set triggerUnit = null
107 set owner = null
108 endmethod
109
110 private method createShrineTrigger takes nothing returns nothing
111 local event triggerEvent
112 local conditionfunc conditionFunction
113 local triggercondition triggerCondition
114 local triggeraction triggerAction
115 set this.m_shrineTrigger = CreateTrigger()
116 set triggerEvent = TriggerRegisterEnterRegion(this.m_shrineTrigger, this.m_discoverRegion, null)
117 set conditionFunction = Condition(function thistype.triggerConditionEnable)
118 set triggerCondition = TriggerAddCondition(this.m_shrineTrigger, conditionFunction)
119 set triggerAction = TriggerAddAction(this.m_shrineTrigger, function thistype.triggerActionEnable)
120 call AHashTable.global().setHandleInteger(this.m_shrineTrigger, "this", this)
121 set triggerEvent = null
122 set conditionFunction = null
123 set triggerCondition = null
124 set triggerAction = null
125 endmethod
126
127 static method create takes destructable usedDestructable, rect discoverRect, rect revivalRect, real facing returns thistype
128 local thistype this = thistype.allocate()
129 //start members
130 set this.m_destructable = usedDestructable
131 debug if (usedDestructable == null) then
132 debug call this.print("Destructable is null!")
133 debug endif
134 set this.m_discoverRect = discoverRect
135 debug if (discoverRect == null) then
136 debug call this.print("Discover rect is null!")
137 debug endif
138 set this.m_revivalRect = revivalRect
139 debug if (revivalRect == null) then
140 debug call this.print("Revival rect is null!")
141 debug endif
142 set this.m_facing = facing
143
144 call this.createDiscoverRegion()
145 call this.createShrineTrigger()
146 return this
147 endmethod
148
149 private method destroyDiscoverRegion takes nothing returns nothing
150 call RemoveRegion(this.m_discoverRegion)
151 set this.m_discoverRegion = null
152 endmethod
153
154 private method destroyShrineTrigger takes nothing returns nothing
155 call AHashTable.global().destroyTrigger(this.m_shrineTrigger)
156 set this.m_shrineTrigger = null
157 endmethod
158
159 private method destroyDiscoverRect takes nothing returns nothing
160 call RemoveRect(this.m_discoverRect)
161 set this.m_discoverRect = null
162 endmethod
163
164 private method destroyDiscoverEffect takes nothing returns nothing
165 if (thistype.effectPath != null) then
166 if (this.m_discoverEffect != null) then
167 call DestroyEffect(this.m_discoverEffect)
168 set this.m_discoverEffect = null
169 endif
170 endif
171 endmethod
172
173 public method onDestroy takes nothing returns nothing
174 //start members
175 set this.m_destructable = null
176
177 call this.destroyDiscoverRegion()
178 call this.destroyShrineTrigger()
179 call this.destroyDiscoverRect()
180 call this.destroyDiscoverEffect()
181 endmethod
182
183 /// @param effectPath If this value is null there is no effect
184 /// @param soundPath If this value is null there is no sound.
185 public static method init takes string effectPath, string soundPath, string textMessage returns nothing
186 //static start members
187 set thistype.effectPath = effectPath
188 set thistype.soundPath = soundPath
189 set thistype.textMessage = textMessage
190
191 if (soundPath != null) then
192 call PreloadSoundPath(soundPath)
193 endif
194 endmethod
195 endstruct
196
197 endlibrary